package musicbrainz;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class ReleaseMB {

	public String mbid;
	public String status;
	public String title;
	public String quality;
	public String language;
	public String script;
	public Date date;
	public String country;
	
	public ReleaseMB(String m, String t, String q, String l, String s, Date d, String c){
		mbid = m;
		title = t;
		quality = q;
		language = l;
		script = s;
		date = d;
		country = c;
	}
	
	public ReleaseMB(String m, String t, String q, String l, String s, String d, String c){
		mbid = m;
		title = t;
		quality = q;
		language = l;
		script = s;
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		try {
			date = (Date)format.parse(d);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		country = c;
	}
	
	public ReleaseMB(Node node){
		try{
			try{
				mbid = node.getAttributes().getNamedItem("id").getNodeValue();
			}catch (Exception e) {
				// TODO: handle exception
			}
			Node nl =  node.getFirstChild();
			try{
				title = nl.getFirstChild().getNodeValue();
			}catch (Exception e) {
				// TODO: handle exception
			}
			nl = nl.getNextSibling();
			try{
				status = nl.getFirstChild().getNodeValue();
			}catch (Exception e) {
				// TODO: handle exception
			}
			nl = nl.getNextSibling();
			try{
				quality = nl.getFirstChild().getNodeValue();
			}catch (Exception e) {
				// TODO: handle exception
			}
			nl = nl.getNextSibling();
			try{
				language = nl.getFirstChild().getFirstChild().getNodeValue();
			}catch (Exception e) {
				// TODO: handle exception
			}
			try{
				script = nl.getFirstChild().getNextSibling().getFirstChild().getNodeValue();
			}catch (Exception e) {
				// TODO: handle exception
			}
			nl = nl.getNextSibling();
			DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
			DateFormat format2 = new SimpleDateFormat("yyyy");
			try {
				date = (Date)format.parse(nl.getFirstChild().getNodeValue());
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				//e.printStackTrace();
				try{
					date = (Date)format2.parse(nl.getFirstChild().getNodeValue());
				}
				catch (Exception e2) {
					// TODO: handle exception
				}
			}
			nl = nl.getNextSibling();
			try{
				country = nl.getFirstChild().getNodeValue();
			}catch (Exception e) {
				// TODO: handle exception
			}
		}catch (Exception e) {
			// TODO: handle exception
		}

	}
	
	/*
	 * <release id="2521ed53-2c54-37fe-8916-c4cc48e883a1">
<title>Beatlemania! With The Beatles</title>
<status>Official</status>
<quality>normal</quality>
<text-representation>
<language>eng</language>
<script>Latn</script>
</text-representation>
<date>1963-11-25</date>
<country>CA</country>
</release>
	 */

}
